<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * 异步操作
*/
define('NOSESSION',true);
require_once '../core/core.php';
if(!$_GET['op']){
	exi('缺少操作参数！');
}
if($_GET['op']=='socket'){
		$socket_url=$_GET['url'];
		$socket_port=$_GET['port'];
		$socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
		socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array("sec" => 30, "usec" => 0));
		socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 30, "usec" => 0));
		if(socket_connect($socket,$socket_url,$socket_port)==false){
			return error('connect fail massege:'.socket_strerror(socket_last_error()));
		}
		$data=base64_encode($_GET['data']);
		$data.="\n";
		socket_write($socket, $data, strlen($data));
		$result=socket_read($socket,1024);
		socket_close($socket);
		$result=json_decode(trim($result),true);
		if(!$result){
			return error('数据发送失败！');
		}
		if($result['type']=='error'){
			return error($result['data']);
		}
		return true;
}
if($_GET['op']=='top'){
	if($_GET['p']){
		if(is_file(ROOT_PLUGIN.$_GET['p'].'/model/api.php')){
			$res=$this->plugin($_GET['p'])->api($_GET['a']);
			exi($res);
		}else{
			return false;
		}
	}else{
		return false;
	}
}